<template>
    <div>
        <h2>添加优惠卷</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>门店名称</td>
                    <td>
                        <select v-model="model.ShopName">
                            <option value="-1">请选择门店</option>
                            <option value="昌平大酒店">昌平大酒店</option>
                            <option value="顺义大酒店">顺义大酒店</option>
                            <option value="温泉大酒店">温泉大酒店</option>
                            <option value="上帝大酒店">上帝大酒店</option>

                        </select>
                    </td>
                </tr>



                <tr>
                    <td>优惠卷类型</td>
                    <td>
                        <select v-model="model.Type">
                            <option value="0">请选择优惠卷类型</option>
                            <option value="折扣卷">折扣卷</option>
                            <option value="优惠卷">优惠卷</option>
                            <option value="优惠卷">优惠卷</option>


                        </select>
                    </td>
                </tr>



                <tr>
                    <td>标题</td>
                    <td>
                        <input type="text" v-model="model.Titel">
                    </td>
                </tr>



                <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="changeImg">
                        <img :src="model.Photo" a width="100" height="100">
                    </td>
                </tr>



                <tr>
                    <td>服务</td>
                    <td>

                        <input type="checkbox" name="yewu" value="订房" v-model="model.FuWu" />订房
                        <input type="checkbox" name="yewu" value="商城" v-model="model.FuWu" />商城
                        <input type="checkbox" name="yewu" v-model="model.FuWu"  value="唐食" />唐食
                        <input type="checkbox" name="yewu"   v-model="model.FuWu"   value="收款码"/>收款码

                    </td>
                </tr>



                <tr>
                    <td>优惠卷开始时间</td>
                    <td><input type="date" v-model="model.BeginTime">-<input type="date" v-model="model.EedTime"></td>

                </tr>


                <tr>
                    <td>优惠价数量</td>
                    <td>
                        <input type="text" v-model="model.Count">
                    </td>
                </tr>


                <tr>
                    <td>限领张数</td>
                    <td>
                        <input type="text" v-model="model.Number">
                    </td>
                </tr>


                <tr>
                    <td>减免金额</td>
                    <td>
                        <input type="text" v-model="model.ReleaseMoney">
                    </td>
                </tr>



                <tr>
                    <td>折扣</td>
                    <td>
                        <input type="text" v-model="model.ZheKou">
                    </td>
                </tr>


                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="ok" class="btn btn-success">
                    </td>
                </tr>


            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();





//图片上传
const changeImg = (e: any) => {

    var obj = e.target.files[0];
    var f = new FormData();
    f.append('file', obj);
    axios({
        url: 'https://localhost:7276/api/DisCount/UpFiles',
        method: 'post',
        data: f,
    })
        .then((res) => {
            model.Photo = res.data;
        })
        .catch((err) => {
            console.log(err);
        })
}


//
let model: any = reactive({

    "ShopName": -1,
    "Type": 0,
    "Titel": '',
    "Photo": '',
    "FuWu": [],
    "BeginTime": '',
    "EedTime": '',
    "Count": '',
    "Number": '',
    "ReleaseMoney": '',
    "ZheKou": '',

})




const ok = () => {
    model.FuWu = model.FuWu.toString();
    axios({
        url: 'https://localhost:7276/api/DisCount/DisAdd',
        method: 'post',
        data: model,
    })
        .then((res) => {
            if (res.data > 0) {
                alert('添加成功');
                router.push('/DisCountList');
                return

            }
            else {
                alert('添加失败');
            }
        })
        .catch((err) => {
            console.log(err);
        })
}

</script>

<style scoped></style>